
package org.sevenblindmice.make24;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import java.util.ArrayList;

public class MainFragment extends Fragment {
    private MyAdapter myAdapter;

    public MainFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_main, container, false);
        MyListView lv = (MyListView) rootView.findViewById(R.id.list);
        TextView errorView = (TextView) rootView.findViewById(R.id.error);
        myAdapter = new MyAdapter(inflater, lv, errorView, savedInstanceState);
        lv.setAdapter(myAdapter);
        lv.setOnItemClickListener(myAdapter);

        ArrayList<View> children = rootView.getTouchables();
        for (View child : children) {
            if (child instanceof Button) {
                child.setOnClickListener(myAdapter);
            }
        }
        return rootView;
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        if (myAdapter != null) {
            myAdapter.save(outState);
        }
    }
}
